package org.jeecg.modules.demo.hydrology.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.jeecg.modules.demo.hydrology.dto.*;
import org.jeecg.modules.demo.hydrology.entity.*;
import org.jeecg.modules.demo.hydrology.mapper.*;
import org.jeecg.modules.demo.hydrology.service.ILargeService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

@Service
public class LargeServiceImpl implements ILargeService {
    @Autowired
    private CgkcdssMapper cgkcdssMapper;
    @Autowired
    private CgkcddyMapper cgkcddyMapper;
    @Autowired
    private CgkcdycMapper cgkcdycMapper;
    @Autowired
    private CgkyjMapper cgkyjMapper;
    @Autowired
    private CscdssMapper cscdssMapper;
    @Autowired
    private CscddyMapper cscddyMapper;
    @Autowired
    private CsyjMapper csyjMapper;
    @Autowired
    private DbcxcdssMapper dbcxcdssMapper;
    @Autowired
    private DbcxyjMapper dbcxyjMapper;
    @Autowired
    private DbcxcddyMapper dbcxcddyMapper;
    @Autowired
    private DbscdssMapper dbscdssMapper;
    @Autowired
    private DbscddyMapper dbscddyMapper;
    @Autowired
    private DbsyjMapper dbsyjMapper;
    @Autowired
    private PslcdssMapper pslcdssMapper;
    @Autowired
    private PslcddyMapper pslcddyMapper;
    @Autowired
    private PslcdycMapper pslcdycMapper;
    @Autowired
    private PslyjMapper pslyjMapper;
    @Autowired
    private WzcdssMapper wzcdssMapper;
    @Autowired
    private WzyjMapper wzyjMapper;
    @Autowired
    private WzcddyMapper wzcddyMapper;
    @Autowired
    private JslcdssMapper jslcdssMapper;
    @Autowired
    private JslcddyMapper jslcddyMapper;
    @Autowired
    private JslyjMapper jslyjMapper;
    @Autowired
    private YslcdssMapper yslcdssMapper;
    @Autowired
    private YslcddyMapper yslcddyMapper;
    @Autowired
    private YslyjMapper yslyjMapper;
    @Autowired
    private SysDepartMapper sysDepartMapper;
    /**
     * 大屏二矿监测数据
     * @return
     */
    @Override
    public List<MonitorDto> getMonitor(String code) {
        List<MonitorDto> dtoList = new ArrayList<>();
        String str = "140421005184";
        switch (code){
            case "0":
                str = "5";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str = "140421005108";
                break;
        }
        MonitorDto monitorDto1 = new MonitorDto();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        QueryWrapper<Cgkcdss> cgkcdssQueryWrapper = new QueryWrapper<>();
        cgkcdssQueryWrapper.eq("org_code", str).orderByDesc("monitor_time");
        List<Cgkcdss> cgkcdssList = cgkcdssMapper.selectList(cgkcdssQueryWrapper);
        monitorDto1.setName("长观孔");
        if (!cgkcdssList.isEmpty()) {
            Cgkcdss cgkcdss = cgkcdssList.get(0);
            monitorDto1.setTime(formatter.format(cgkcdss.getMonitorTime()));
            monitorDto1.setValue(cgkcdss.getWaterLevel().toString());
            QueryWrapper<Cgkcddy> cgkcddyQueryWrapper = new QueryWrapper<>();
            cgkcddyQueryWrapper.eq("station_code", cgkcdss.getStationCode());
            Cgkcddy cgkcddy = cgkcddyMapper.selectOne(cgkcddyQueryWrapper);
            if (cgkcddy != null) {
                monitorDto1.setLocation(cgkcddy.getEquipmentPosition());
            }
        }
        MonitorDto monitorDto2 = new MonitorDto();
        QueryWrapper<Cscdss> cscdssQueryWrapper = new QueryWrapper<>();
        cscdssQueryWrapper.eq("station_mine", str).orderByDesc("data_time");
        List<Cscdss> cscdsses = cscdssMapper.selectList(cscdssQueryWrapper);
        monitorDto2.setName("抽放水");
        if (!cscdsses.isEmpty()) {
            Cscdss cscdss = cscdsses.get(0);
            monitorDto2.setTime(formatter.format(cscdss.getDataTime()));
            monitorDto2.setValue(cscdss.getDrainageAmount().toString());
            QueryWrapper<Cscddy> cscddyQueryWrapper = new QueryWrapper<>();
            cscddyQueryWrapper.eq("station_code", cscdss.getStationCode());
            Cscddy cscddy = cscddyMapper.selectOne(cscddyQueryWrapper);
            if (cscddy != null) {
                monitorDto2.setLocation(cscddy.getEquipmentPosition());
            }
        }
        MonitorDto monitorDto3 = new MonitorDto();
        QueryWrapper<Dbcxcdss> dbcxcdssQueryWrapper = new QueryWrapper<>();
        dbcxcdssQueryWrapper.eq("station_code", str).orderByDesc("data_time");
        List<Dbcxcdss> dbcxcdsses = dbcxcdssMapper.selectList(dbcxcdssQueryWrapper);
        monitorDto3.setName("地表沉陷");
        if (!dbcxcdsses.isEmpty()) {
            Dbcxcdss dbcxcdss = dbcxcdsses.get(0);
            monitorDto3.setValue(dbcxcdss.getMiningDepth());
            monitorDto3.setTime(formatter.format(dbcxcdss.getDataTime()));
            QueryWrapper<Dbcxcddy> dbcxcddyQueryWrapper = new QueryWrapper<>();
            dbcxcddyQueryWrapper.eq("station_code", dbcxcdss.getStationCode());
            Dbcxcddy dbcxcddy = dbcxcddyMapper.selectOne(dbcxcddyQueryWrapper);
            if (dbcxcddy != null) {
                monitorDto3.setLocation(dbcxcddy.getRegionName());
            }
        }
        MonitorDto monitorDto4 = new MonitorDto();
        QueryWrapper<Dbscdss> dbscdssQueryWrapper = new QueryWrapper<>();
        dbscdssQueryWrapper.eq("station_mine", str).orderByDesc("monitor_time");
        List<Dbscdss> dbscdsses = dbscdssMapper.selectList(dbscdssQueryWrapper);
        monitorDto4.setName("地表水");
        if (!dbscdsses.isEmpty()) {
            Dbscdss dbscdss = dbscdsses.get(0);
            monitorDto4.setValue(dbscdss.getValue().toString());
            monitorDto4.setTime(formatter.format(dbscdss.getMonitorTime()));
            QueryWrapper<Dbscddy> dbscddyQueryWrapper = new QueryWrapper<>();
            dbscddyQueryWrapper.eq("station_code", dbscdss.getStationCode());
            Dbscddy dbscddy = dbscddyMapper.selectOne(dbscddyQueryWrapper);
            if (dbscddy != null) {
                monitorDto4.setLocation(dbscddy.getEquipmentPosition());
            }
        }
        MonitorDto monitorDto5 = new MonitorDto();
        QueryWrapper<Jslcdss> jslcdssQueryWrapper = new QueryWrapper<>();
        jslcdssQueryWrapper.eq("station_mine", str).orderByDesc("monitor_time");
        List<Jslcdss> jslcdsses = jslcdssMapper.selectList(jslcdssQueryWrapper);
        monitorDto5.setName("降水量");
        if (!jslcdsses.isEmpty()) {
            Jslcdss jslcdss = jslcdsses.get(0);
            monitorDto5.setValue(jslcdss.getValue().toString());
            monitorDto5.setTime(formatter.format(jslcdss.getMonitorTime()));
            QueryWrapper<Jslcddy> jslcddyQueryWrapper = new QueryWrapper<>();
            jslcddyQueryWrapper.eq("station_code", jslcdss.getStationCode());
            Jslcddy jslcddy = jslcddyMapper.selectOne(jslcddyQueryWrapper);
            if (jslcddy != null) {
                monitorDto5.setLocation(jslcddy.getEquipmentPosition());
            }
        }
        MonitorDto monitorDto6 = new MonitorDto();
        QueryWrapper<Pslcdss> pslcdssQueryWrapper = new QueryWrapper<>();
        pslcdssQueryWrapper.eq("station_mine", str).orderByDesc("monitor_time");
        List<Pslcdss> pslcdsses = pslcdssMapper.selectList(pslcdssQueryWrapper);
        monitorDto6.setName("排水量");
        if (!pslcdsses.isEmpty()) {
            Pslcdss pslcdss = pslcdsses.get(0);
            monitorDto6.setValue(pslcdss.getValue().toString());
            monitorDto6.setTime(formatter.format(pslcdss.getMonitorTime()));
            QueryWrapper<Pslcddy> pslcddyQueryWrapper = new QueryWrapper<>();
            pslcddyQueryWrapper.eq("station_code", pslcdss.getStationCode());
            Pslcddy pslcddy = pslcddyMapper.selectOne(pslcddyQueryWrapper);
            if (pslcddy != null) {
                monitorDto6.setLocation(pslcddy.getEquipmentPosition());
            }
        }
        MonitorDto monitorDto7 = new MonitorDto();
        QueryWrapper<Wzcdss> wzcdssQueryWrapper = new QueryWrapper<>();
        wzcdssQueryWrapper.eq("station_mine", str).orderByDesc("occurred_time");
        List<Wzcdss> wzcdsses = wzcdssMapper.selectList(wzcdssQueryWrapper);
        monitorDto7.setName("微震");
        if (!wzcdsses.isEmpty()) {
            Wzcdss wzcdss = wzcdsses.get(0);
            monitorDto7.setValue(wzcdss.getSeismicEnergy().toString());
            monitorDto7.setTime(formatter.format(wzcdss.getOccurredTime()));
            QueryWrapper<Wzcddy> wzcddyQueryWrapper = new QueryWrapper<>();
            wzcddyQueryWrapper.eq("station_code", wzcdss.getEventCode());
            Wzcddy wzcddy = wzcddyMapper.selectOne(wzcddyQueryWrapper);
            if (wzcddy != null) {
                monitorDto7.setLocation(wzcddy.getEquipmentPosition());
            }
        }
        MonitorDto monitorDto8 = new MonitorDto();
        QueryWrapper<Yslcdss> yslcdssQueryWrapper = new QueryWrapper<>();
        yslcdssQueryWrapper.eq("station_mine", str).orderByDesc("monitor_time");
        List<Yslcdss> yslcdsses = yslcdssMapper.selectList(yslcdssQueryWrapper);
        monitorDto8.setName("涌水量");
        if (!yslcdsses.isEmpty()) {
            Yslcdss yslcdss = yslcdsses.get(0);
            monitorDto8.setValue(yslcdss.getValue());
            monitorDto8.setTime(formatter.format(yslcdss.getMonitorTime()));
            QueryWrapper<Yslcddy> yslcddyQueryWrapper = new QueryWrapper<>();
            yslcddyQueryWrapper.eq("station_code", yslcdss.getPointCode());
            Yslcddy yslcddy = yslcddyMapper.selectOne(yslcddyQueryWrapper);
            if (yslcddy != null) {
                monitorDto8.setLocation(yslcddy.getEquipmentPosition());
            }
        }
        dtoList.add(monitorDto1);
        dtoList.add(monitorDto2);
        dtoList.add(monitorDto3);
        dtoList.add(monitorDto4);
        dtoList.add(monitorDto5);
        dtoList.add(monitorDto6);
        dtoList.add(monitorDto7);
        dtoList.add(monitorDto8);
        return dtoList;
    }

    /**
     * 排水量实时统计数据
     *
     * @param date
     * @return
     */
    @Override
    public List<PslTotalDto> getPslTotal(String date) {
        List<LocalDate> dates = getDate(date);
        List<PslTotalDto> pslTotalDtos = new ArrayList<>();
        QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
        List<SysDepart> sysDeparts = sysDepartMapper.selectList(sysDepartQueryWrapper.eq("parent_id", "1779765508718002177"));
        PslTotalDto pslTotalDto;
        for (SysDepart sysDepart : sysDeparts) {
            QueryWrapper<Pslcddy> pslcddyQueryWrapper = new QueryWrapper<>();
            pslcddyQueryWrapper.eq("station_mine", sysDepart.getOrgCode());
            List<Pslcddy> pslcddys = pslcddyMapper.selectList(pslcddyQueryWrapper);
            for (Pslcddy pslcddy : pslcddys) {
                pslTotalDto = new PslTotalDto();
                pslTotalDto.setStationName(sysDepart.getDepartName());
                pslTotalDto.setStationCode(pslcddy.getStationCode());
                pslTotalDto.setLocation(pslcddy.getEquipmentPosition());
                QueryWrapper<Pslcdss> pslcdssQueryWrapper = new QueryWrapper<>();
                pslcdssQueryWrapper.between("monitor_time",dates.get(0),dates.get(1)).eq("station_code",pslcddy.getStationCode());
                List<Pslcdss> pslcdsses = pslcdssMapper.selectList(pslcdssQueryWrapper);
                Double count = 0.0;
                for (Pslcdss pslcdss : pslcdsses) {
                    count += pslcdss.getValue().doubleValue();
                }
                pslTotalDto.setValue(count.toString());
                pslTotalDtos.add(pslTotalDto);
            }
        }
        return pslTotalDtos;
    }

    /**
     * 折线数据
     *
     * @param date
     * @param code
     * @return
     */
    @Override
    public List<HydrologyReportDto> getLineTotal(String date, String code) {
        DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm");
        DateTimeFormatter DAY_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
        DateTimeFormatter MONTH_FORMAT = DateTimeFormatter.ofPattern("MM-dd");

        List<String> dateList = new ArrayList<>();
        List<LocalDate> dates = new ArrayList<>();
        List<HydrologyReportDto> hydrologyReportDtoList = new ArrayList<>();
        // 根据输入长度确定格式
        if (date.length() == 4) {
            // 只有年份，生成该年份所有月份的列表
            int year = Integer.parseInt(date);
            for (int month = 1; month <= 12; month++) {
                dateList.add(String.format("%d-%02d", year, month));
                LocalDate startDate = LocalDate.of(year, month, 1);
                dates.add(LocalDate.parse(startDate.format(DATE_FORMAT)));
            }
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            List<SysDepart> sysDeparts = sysDepartMapper.selectList(sysDepartQueryWrapper.eq("parent_id", "1779765508718002177"));
            HydrologyReportDto hydrologyReportDto;
            for (SysDepart sysDepart : sysDeparts) {
                List<String> totalList = new ArrayList<>();
                switch (code) {
                    case "排水量":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate.plusMonths(1), LocalTime.MIN);
                            QueryWrapper<Pslcdss> pslcdssQueryWrapper = new QueryWrapper<>();
                            pslcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Pslcdss> pslcdsses = pslcdssMapper.selectList(pslcdssQueryWrapper);
                            Double count = 0.0;
                            for (Pslcdss pslcdss : pslcdsses) {
                                count += pslcdss.getValue().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "疏放水":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate.plusMonths(1), LocalTime.MIN);
                            QueryWrapper<Cscdss> cscdssQueryWrapper = new QueryWrapper<>();
                            cscdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("data_time",beginTime,endTime);
                            List<Cscdss> cscdsses = cscdssMapper.selectList(cscdssQueryWrapper);
                            Double count = 0.0;
                            for (Cscdss cscdss : cscdsses) {
                                count += cscdss.getDrainageAmount().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "长观孔":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate.plusMonths(1), LocalTime.MIN);
                            QueryWrapper<Cgkcdss> cgkcdssQueryWrapper = new QueryWrapper<>();
                            cgkcdssQueryWrapper.eq("org_code",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Cgkcdss> cgkcdsses = cgkcdssMapper.selectList(cgkcdssQueryWrapper);
                            Double count = 0.0;
                            for (Cgkcdss cgkcdss : cgkcdsses) {
                                count += cgkcdss.getWaterLevel().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "降雨量":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate.plusMonths(1), LocalTime.MIN);
                            QueryWrapper<Jslcdss> jslcdssQueryWrapper = new QueryWrapper<>();
                            jslcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Jslcdss> jslcdsses = jslcdssMapper.selectList(jslcdssQueryWrapper);
                            Double count = 0.0;
                            for (Jslcdss jslcdss : jslcdsses) {
                                count += jslcdss.getValue().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "地表岩移":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate.plusMonths(1), LocalTime.MIN);
                            QueryWrapper<Dbcxcdss> dbcxcdssQueryWrapper = new QueryWrapper<>();
                            dbcxcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("data_time",beginTime,endTime);
                            List<Dbcxcdss> dbcxcdsses = dbcxcdssMapper.selectList(dbcxcdssQueryWrapper);
                            Double count = 0.0;
                            for (Dbcxcdss dbcxcdss : dbcxcdsses) {
                                count += dbcxcdss.getCoordinateX().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "地表水":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate.plusMonths(1), LocalTime.MIN);
                            QueryWrapper<Dbscdss> dbscdssQueryWrapper = new QueryWrapper<>();
                            dbscdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Dbscdss> dbscdsses = dbscdssMapper.selectList(dbscdssQueryWrapper);
                            Double count = 0.0;
                            for (Dbscdss dbscdss : dbscdsses) {
                                count += dbscdss.getValue().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "涌水量":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate.plusMonths(1), LocalTime.MIN);
                            QueryWrapper<Yslcdss> yslcdssQueryWrapper = new QueryWrapper<>();
                            yslcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Yslcdss> yslcdsses = yslcdssMapper.selectList(yslcdssQueryWrapper);
                            Double count = 0.0;
                            for (Yslcdss yslcdss : yslcdsses) {
                                Double ysl = Double.valueOf(yslcdss.getValue());
                                count += ysl;
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                }
            }
        } else if (date.length() == 7) {
            // 年份和月份，默认日期为1，结束日期为下一个月第一天的前一天
            LocalDate startDate = LocalDate.parse(date + "-01", DATE_FORMAT);
            LocalDate endDate = startDate.plusMonths(1).minusDays(1); // 获取下一个月第一天的前一天
            LocalDate start = LocalDate.parse(startDate.format(DATE_FORMAT));
            LocalDate end = LocalDate.parse(endDate.format(DATE_FORMAT));
            dates.add(start);
            while (!start.equals(end)) {
                start = start.plusDays(1);
                dates.add(start);
            }
            for (LocalDate localDate : dates) {
                String format = localDate.format(MONTH_FORMAT);
                dateList.add(format);
            }
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            List<SysDepart> sysDeparts = sysDepartMapper.selectList(sysDepartQueryWrapper.eq("parent_id", "1779765508718002177"));
            HydrologyReportDto hydrologyReportDto;
            for (SysDepart sysDepart : sysDeparts) {
                List<String> totalList = new ArrayList<>();
                switch (code) {
                    case "排水量":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate, LocalTime.MAX);
                            QueryWrapper<Pslcdss> pslcdssQueryWrapper = new QueryWrapper<>();
                            pslcdssQueryWrapper.between("monitor_time",beginTime,endTime).eq("station_mine",sysDepart.getOrgCode());
                            List<Pslcdss> pslcdsses = pslcdssMapper.selectList(pslcdssQueryWrapper);
                            Double count = 0.0;
                            for (Pslcdss pslcdss : pslcdsses) {
                                count += pslcdss.getValue().doubleValue();
                            }
                           totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "疏放水":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate, LocalTime.MAX);
                            QueryWrapper<Cscdss> cscdssQueryWrapper = new QueryWrapper<>();
                            cscdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("data_time",beginTime,endTime);
                            List<Cscdss> cscdsses = cscdssMapper.selectList(cscdssQueryWrapper);
                            Double count = 0.0;
                            for (Cscdss cscdss : cscdsses) {
                                count += cscdss.getDrainageAmount().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "长观孔":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate, LocalTime.MAX);
                            QueryWrapper<Cgkcdss> cgkcdssQueryWrapper = new QueryWrapper<>();
                            cgkcdssQueryWrapper.eq("org_code",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Cgkcdss> cgkcdsses = cgkcdssMapper.selectList(cgkcdssQueryWrapper);
                            Double count = 0.0;
                            for (Cgkcdss cgkcdss : cgkcdsses) {
                                count += cgkcdss.getWaterLevel().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "降雨量":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate, LocalTime.MAX);
                            QueryWrapper<Jslcdss> jslcdssQueryWrapper = new QueryWrapper<>();
                            jslcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Jslcdss> jslcdsses = jslcdssMapper.selectList(jslcdssQueryWrapper);
                            Double count = 0.0;
                            for (Jslcdss jslcdss : jslcdsses) {
                                count += jslcdss.getValue().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "地表岩移":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate, LocalTime.MAX);
                            QueryWrapper<Dbcxcdss> dbcxcdssQueryWrapper = new QueryWrapper<>();
                            dbcxcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("data_time",beginTime,endTime);
                            List<Dbcxcdss> dbcxcdsses = dbcxcdssMapper.selectList(dbcxcdssQueryWrapper);
                            Double count = 0.0;
                            for (Dbcxcdss dbcxcdss : dbcxcdsses) {
                                count += dbcxcdss.getCoordinateX().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "地表水":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate, LocalTime.MAX);
                            QueryWrapper<Dbscdss> dbscdssQueryWrapper = new QueryWrapper<>();
                            dbscdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Dbscdss> dbscdsses = dbscdssMapper.selectList(dbscdssQueryWrapper);
                            Double count = 0.0;
                            for (Dbscdss dbscdss : dbscdsses) {
                                count += dbscdss.getValue().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "涌水量":
                        for (LocalDate localDate : dates) {
                            LocalDateTime beginTime = LocalDateTime.of(localDate, LocalTime.MIN);
                            LocalDateTime endTime = LocalDateTime.of(localDate, LocalTime.MAX);
                            QueryWrapper<Yslcdss> yslcdssQueryWrapper = new QueryWrapper<>();
                            yslcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Yslcdss> yslcdsses = yslcdssMapper.selectList(yslcdssQueryWrapper);
                            Double count = 0.0;
                            for (Yslcdss yslcdss : yslcdsses) {
                                Double ysl = Double.valueOf(yslcdss.getValue());
                                count += ysl;
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                }
            }
        } else if (date.length() == 10) {
            // 年份、月份和日期
            LocalDate time = LocalDate.parse(date, DATE_FORMAT);

            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            List<SysDepart> sysDeparts = sysDepartMapper.selectList(sysDepartQueryWrapper.eq("parent_id", "1779765508718002177"));
            HydrologyReportDto hydrologyReportDto;
            for (SysDepart sysDepart : sysDeparts) {
                List<String> totalList = new ArrayList<>();
                switch (code) {
                    case "排水量":
                        for (int hour = 0; hour < 24; hour++) {
                            dateList.add(TIME_FORMAT.format(LocalTime.of(hour, 0)));
                            LocalDateTime beginTime = LocalDateTime.of(time, LocalTime.of(hour, 0));
                            LocalDateTime endTime = LocalDateTime.of(time, LocalTime.of(hour, 59));
                            QueryWrapper<Pslcdss> pslcdssQueryWrapper = new QueryWrapper<>();
                            pslcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Pslcdss> pslcdsses = pslcdssMapper.selectList(pslcdssQueryWrapper);
                            Double count = 0.0;
                            for (Pslcdss pslcdss : pslcdsses) {
                                count += pslcdss.getValue().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "疏放水":
                        for (int hour = 0; hour < 24; hour++) {
                            dateList.add(TIME_FORMAT.format(LocalTime.of(hour, 0)));
                            LocalDateTime beginTime = LocalDateTime.of(time, LocalTime.of(hour, 0));
                            LocalDateTime endTime = LocalDateTime.of(time, LocalTime.of(hour, 59));
                            QueryWrapper<Cscdss> cscdssQueryWrapper = new QueryWrapper<>();
                            cscdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("data_time",beginTime,endTime);
                            List<Cscdss> cscdsses = cscdssMapper.selectList(cscdssQueryWrapper);
                            Double count = 0.0;
                            for (Cscdss cscdss : cscdsses) {
                                count += cscdss.getDrainageAmount().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "长观孔":
                        for (int hour = 0; hour < 24; hour++) {
                            dateList.add(TIME_FORMAT.format(LocalTime.of(hour, 0)));
                            LocalDateTime beginTime = LocalDateTime.of(time, LocalTime.of(hour, 0));
                            LocalDateTime endTime = LocalDateTime.of(time, LocalTime.of(hour, 59));
                            QueryWrapper<Cgkcdss> cgkcdssQueryWrapper = new QueryWrapper<>();
                            cgkcdssQueryWrapper.eq("org_code",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Cgkcdss> cgkcdsses = cgkcdssMapper.selectList(cgkcdssQueryWrapper);
                            Double count = 0.0;
                            for (Cgkcdss cgkcdss : cgkcdsses) {
                                count += cgkcdss.getWaterLevel().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "降雨量":
                        for (int hour = 0; hour < 24; hour++) {
                            dateList.add(TIME_FORMAT.format(LocalTime.of(hour, 0)));
                            LocalDateTime beginTime = LocalDateTime.of(time, LocalTime.of(hour, 0));
                            LocalDateTime endTime = LocalDateTime.of(time, LocalTime.of(hour, 59));
                            QueryWrapper<Jslcdss> jslcdssQueryWrapper = new QueryWrapper<>();
                            jslcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Jslcdss> jslcdsses = jslcdssMapper.selectList(jslcdssQueryWrapper);
                            Double count = 0.0;
                            for (Jslcdss jslcdss : jslcdsses) {
                                count += jslcdss.getValue().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "地表岩移":
                        for (int hour = 0; hour < 24; hour++) {
                            dateList.add(TIME_FORMAT.format(LocalTime.of(hour, 0)));
                            LocalDateTime beginTime = LocalDateTime.of(time, LocalTime.of(hour, 0));
                            LocalDateTime endTime = LocalDateTime.of(time, LocalTime.of(hour, 59));
                            QueryWrapper<Dbcxcdss> dbcxcdssQueryWrapper = new QueryWrapper<>();
                            dbcxcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("data_time",beginTime,endTime);
                            List<Dbcxcdss> dbcxcdsses = dbcxcdssMapper.selectList(dbcxcdssQueryWrapper);
                            Double count = 0.0;
                            for (Dbcxcdss dbcxcdss : dbcxcdsses) {
                                count += dbcxcdss.getCoordinateX().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "地表水":
                        for (int hour = 0; hour < 24; hour++) {
                            dateList.add(TIME_FORMAT.format(LocalTime.of(hour, 0)));
                            LocalDateTime beginTime = LocalDateTime.of(time, LocalTime.of(hour, 0));
                            LocalDateTime endTime = LocalDateTime.of(time, LocalTime.of(hour, 59));
                            QueryWrapper<Dbscdss> dbscdssQueryWrapper = new QueryWrapper<>();
                            dbscdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Dbscdss> dbscdsses = dbscdssMapper.selectList(dbscdssQueryWrapper);
                            Double count = 0.0;
                            for (Dbscdss dbscdss : dbscdsses) {
                                count += dbscdss.getValue().doubleValue();
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                    case "涌水量":
                        for (int hour = 0; hour < 24; hour++) {
                            dateList.add(TIME_FORMAT.format(LocalTime.of(hour, 0)));
                            LocalDateTime beginTime = LocalDateTime.of(time, LocalTime.of(hour, 0));
                            LocalDateTime endTime = LocalDateTime.of(time, LocalTime.of(hour, 59));
                            QueryWrapper<Yslcdss> yslcdssQueryWrapper = new QueryWrapper<>();
                            yslcdssQueryWrapper.eq("station_mine",sysDepart.getOrgCode()).between("monitor_time",beginTime,endTime);
                            List<Yslcdss> yslcdsses = yslcdssMapper.selectList(yslcdssQueryWrapper);
                            Double count = 0.0;
                            for (Yslcdss yslcdss : yslcdsses) {
                                Double ysl = Double.valueOf(yslcdss.getValue());
                                count += ysl;
                            }
                            totalList.add(count.toString());
                        }
                        hydrologyReportDto = new HydrologyReportDto();
                        hydrologyReportDto.setTotal(totalList);
                        hydrologyReportDto.setDateList(dateList.toString());
                        hydrologyReportDtoList.add(hydrologyReportDto);
                        break;
                }
            }
        } else {
            throw new IllegalArgumentException("Invalid date format: " + date);
        }
        return hydrologyReportDtoList;
    }

    /**
     * 煤矿列表及其状态
     * @return
     */
    @Override
    public List<listMineDto> getListMine() {
        List<listMineDto> mineDtoList=new ArrayList<>();
        QueryWrapper<SysDepart> sysDepartQueryWrapper=new QueryWrapper<>();
        sysDepartQueryWrapper.ne("parent_id","");
        List<SysDepart> sysDepartList=sysDepartMapper.selectList(sysDepartQueryWrapper);
        mineDtoList=sysDepartList.stream().map(dto->{
            listMineDto listMineDto=new listMineDto();
            listMineDto.setMineName(dto.getDepartName());
            String str=dto.getOrgCode();
            int number=0;
            QueryWrapper<Cgkcdss> cgkcdssQueryWrapper = new QueryWrapper<>();
            number +=cgkcdssMapper.selectCount(cgkcdssQueryWrapper.eq("org_code",str));
            QueryWrapper<Cscdss> cscdssQueryWrapper = new QueryWrapper<>();
            number +=cscdssMapper.selectCount(cscdssQueryWrapper.eq("station_mine",str));
            QueryWrapper<Dbcxcdss> dbcxcdssQueryWrapper = new QueryWrapper<>();
            number +=dbcxcdssMapper.selectCount(dbcxcdssQueryWrapper.eq("station_mine",str));
            QueryWrapper<Dbscdss> dbscdssQueryWrapper = new QueryWrapper<>();
            number +=dbscdssMapper.selectCount(dbscdssQueryWrapper.eq("station_mine",str));
            QueryWrapper<Jslcdss> jslcdssQueryWrapper = new QueryWrapper<>();
            number +=jslcdssMapper.selectCount(jslcdssQueryWrapper.eq("station_mine",str));
            QueryWrapper<Pslcdss> pslcdssQueryWrapper = new QueryWrapper<>();
            number +=pslcdssMapper.selectCount(pslcdssQueryWrapper.eq("station_mine",str));
            QueryWrapper<Wzcdss> wzcdssQueryWrapper = new QueryWrapper<>();
            number +=wzcdssMapper.selectCount(wzcdssQueryWrapper.eq("station_mine",str));
            QueryWrapper<Yslcdss> yslcdssQueryWrapper = new QueryWrapper<>();
            number +=yslcdssMapper.selectCount(yslcdssQueryWrapper.eq("station_mine",str));
            if (number !=0){
                listMineDto.setMineCode("1");
            }else {
                listMineDto.setMineCode("0");
            }
            return listMineDto;
        }).collect(Collectors.toList());
        return mineDtoList;
    }


    /**
     * 统计时间处理
     *
     * @param dateString
     * @return
     */
    protected List<LocalDate> getDate(String dateString) {
        DateTimeFormatter inputFormatter;
        DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        List<LocalDate> timeRange = new ArrayList<>();

        // 根据输入长度确定格式
        if (dateString.length() == 4) {
            // 只有年份，默认月份和日期为1，结束日期为下一年第一天的前一天
            int year = Integer.parseInt(dateString);
            LocalDate startDate = LocalDate.of(year, 1, 1);
            LocalDate endDate = startDate.plusYears(1).minusDays(1); // 获取下一年第一天的前一天
            timeRange.add(LocalDate.parse(startDate.format(outputFormatter)));
            timeRange.add(LocalDate.parse(endDate.format(outputFormatter)));
        } else if (dateString.length() == 7) {
            // 年份和月份，默认日期为1，结束日期为下一个月第一天的前一天
            LocalDate startDate = LocalDate.parse(dateString + "-01", outputFormatter);
            LocalDate endDate = startDate.plusMonths(1).minusDays(1); // 获取下一个月第一天的前一天
            timeRange.add(LocalDate.parse(startDate.format(outputFormatter)));
            timeRange.add(LocalDate.parse(endDate.format(outputFormatter)));
        } else if (dateString.length() == 10) {
            // 年份、月份和日期
            LocalDate date = LocalDate.parse(dateString, outputFormatter);
            timeRange.add(LocalDate.parse(date.format(outputFormatter)));
            LocalDate endDate = date.plusDays(1);
            timeRange.add(LocalDate.parse(endDate.format(outputFormatter)));
        } else {
            throw new IllegalArgumentException("Invalid date format: " + dateString);
        }
        return timeRange;
    }

    /**
     * 集团预警和值
     *
     * @return
     */
    @Override
    public LargeDto getTotalAlarm() {
        List<LargeDto> alarms = getAlarms();
        int alarmLevel1 = 0;
        int alarmLevel2 = 0;
        int alarmLevel3 = 0;
        int alarmLevel4 = 0;
        for (LargeDto alarm : alarms) {
            alarmLevel1 += Integer.parseInt(alarm.getAlarmLevel1());
            alarmLevel2 += Integer.parseInt(alarm.getAlarmLevel2());
            alarmLevel3 += Integer.parseInt(alarm.getAlarmLevel3());
            alarmLevel4 += Integer.parseInt(alarm.getAlarmLevel4());
        }
        LargeDto largeDto = new LargeDto();
        largeDto.setAlarmLevel1(String.valueOf(alarmLevel1));
        largeDto.setAlarmLevel2(String.valueOf(alarmLevel2));
        largeDto.setAlarmLevel3(String.valueOf(alarmLevel3));
        largeDto.setAlarmLevel4(String.valueOf(alarmLevel4));
        return largeDto;
    }

    /**
     * 分类统计
     *
     * @return
     */
    @Override
    public List<CategoryDto> getCategory() {
        List<CategoryDto> categoryDtos = new ArrayList<>();
        QueryWrapper<Cgkyj> queryWrapper1 = new QueryWrapper<>();
        Long cgkLong = cgkyjMapper.selectCount(queryWrapper1);
        CategoryDto categoryDto1 = new CategoryDto();
        categoryDto1.setCategoryCount(cgkLong.toString());
        categoryDtos.add(categoryDto1);
        QueryWrapper<Csyj> queryWrapper2 = new QueryWrapper<>();
        Long csLong = csyjMapper.selectCount(queryWrapper2);
        CategoryDto categoryDto2 = new CategoryDto();
        categoryDto2.setCategoryCount(csLong.toString());
        categoryDtos.add(categoryDto2);
        QueryWrapper<Dbcxyj> queryWrapper3 = new QueryWrapper<>();
        Long dbcxLong = dbcxyjMapper.selectCount(queryWrapper3);
        CategoryDto categoryDto3 = new CategoryDto();
        categoryDto3.setCategoryCount(dbcxLong.toString());
        categoryDtos.add(categoryDto3);
        QueryWrapper<Dbsyj> queryWrapper4 = new QueryWrapper<>();
        Long dbsLong = dbsyjMapper.selectCount(queryWrapper4);
        CategoryDto categoryDto4 = new CategoryDto();
        categoryDto4.setCategoryCount(dbsLong.toString());
        categoryDtos.add(categoryDto4);
        QueryWrapper<Jslyj> queryWrapper5 = new QueryWrapper<>();
        Long jslLong = jslyjMapper.selectCount(queryWrapper5);
        CategoryDto categoryDto5 = new CategoryDto();
        categoryDto5.setCategoryCount(jslLong.toString());
        categoryDtos.add(categoryDto5);
        QueryWrapper<Pslyj> queryWrapper6 = new QueryWrapper<>();
        Long pslLong = pslyjMapper.selectCount(queryWrapper6);
        CategoryDto categoryDto6 = new CategoryDto();
        categoryDto6.setCategoryCount(pslLong.toString());
        categoryDtos.add(categoryDto6);
        QueryWrapper<Wzyj> queryWrapper7 = new QueryWrapper<>();
        Long wzLong = wzyjMapper.selectCount(queryWrapper7);
        CategoryDto categoryDto7 = new CategoryDto();
        categoryDto7.setCategoryCount(wzLong.toString());
        categoryDtos.add(categoryDto7);
        QueryWrapper<Yslyj> queryWrapper8 = new QueryWrapper<>();
        Long yslLong = yslyjMapper.selectCount(queryWrapper8);
        CategoryDto categoryDto8 = new CategoryDto();
        categoryDto8.setCategoryCount(yslLong.toString());
        categoryDtos.add(categoryDto8);
        return categoryDtos;
    }

    /**
     * 告警处理统计
     *
     * @return
     */
    @Override
    public List<Integer> getHandle() {
        List<Integer> list = new ArrayList<>();
        QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
        List<SysDepart> sysDeparts = sysDepartMapper.selectList(sysDepartQueryWrapper.eq("parent_id", "1779765508718002177"));
        for (SysDepart sysDepart : sysDeparts) {
            QueryWrapper<Cgkyj> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("station_mine", sysDepart.getOrgCode());
            Long cgkLong = cgkyjMapper.selectCount(queryWrapper1);
            QueryWrapper<Cgkyj> queryWrapper11 = new QueryWrapper<>();
            queryWrapper11.eq("station_mine", sysDepart.getOrgCode()).eq("alarm_status", 1);
            Long cgkLong1 = cgkyjMapper.selectCount(queryWrapper11);

            QueryWrapper<Csyj> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("station_mine", sysDepart.getOrgCode());
            Long csLong = csyjMapper.selectCount(queryWrapper2);
            QueryWrapper<Csyj> queryWrapper21 = new QueryWrapper<>();
            queryWrapper21.eq("station_mine", sysDepart.getOrgCode()).eq("alarm_status", 1);
            Long csLong1 = csyjMapper.selectCount(queryWrapper21);

            QueryWrapper<Dbcxyj> queryWrapper3 = new QueryWrapper<>();
            queryWrapper3.eq("station_mine", sysDepart.getOrgCode());
            Long dbcxLong = dbcxyjMapper.selectCount(queryWrapper3);
            QueryWrapper<Dbcxyj> queryWrapper31 = new QueryWrapper<>();
            queryWrapper31.eq("station_mine", sysDepart.getOrgCode()).eq("alarm_status", 1);
            Long dbcxLong1 = dbcxyjMapper.selectCount(queryWrapper31);

            QueryWrapper<Dbsyj> queryWrapper4 = new QueryWrapper<>();
            queryWrapper4.eq("station_mine", sysDepart.getOrgCode());
            Long dbsLong = dbsyjMapper.selectCount(queryWrapper4);
            QueryWrapper<Dbsyj> queryWrapper41 = new QueryWrapper<>();
            queryWrapper41.eq("station_mine", sysDepart.getOrgCode()).eq("alarm_status", 1);
            Long dbsLong1 = dbsyjMapper.selectCount(queryWrapper41);

            QueryWrapper<Jslyj> queryWrapper5 = new QueryWrapper<>();
            queryWrapper5.eq("station_mine", sysDepart.getOrgCode());
            Long jslLong = jslyjMapper.selectCount(queryWrapper5);
            QueryWrapper<Jslyj> queryWrapper51 = new QueryWrapper<>();
            queryWrapper51.eq("station_mine", sysDepart.getOrgCode()).eq("alarm_status", 1);
            Long jslLong1 = jslyjMapper.selectCount(queryWrapper51);

            QueryWrapper<Pslyj> queryWrapper6 = new QueryWrapper<>();
            queryWrapper6.eq("station_mine", sysDepart.getOrgCode());
            Long pslLong = pslyjMapper.selectCount(queryWrapper6);
            QueryWrapper<Pslyj> queryWrapper61 = new QueryWrapper<>();
            queryWrapper61.eq("station_mine", sysDepart.getOrgCode()).eq("alarm_status", 1);
            Long pslLong1 = pslyjMapper.selectCount(queryWrapper61);

            QueryWrapper<Wzyj> queryWrapper7 = new QueryWrapper<>();
            queryWrapper7.eq("station_mine", sysDepart.getOrgCode());
            Long wzLong = wzyjMapper.selectCount(queryWrapper7);
            QueryWrapper<Wzyj> queryWrapper71 = new QueryWrapper<>();
            queryWrapper71.eq("station_mine", sysDepart.getOrgCode()).eq("alarm_status", 1);
            Long wzLong1 = wzyjMapper.selectCount(queryWrapper71);

            QueryWrapper<Yslyj> queryWrapper8 = new QueryWrapper<>();
            queryWrapper8.eq("station_mine", sysDepart.getOrgCode());
            Long yslLong = yslyjMapper.selectCount(queryWrapper8);
            QueryWrapper<Yslyj> queryWrapper81 = new QueryWrapper<>();
            queryWrapper81.eq("station_mine", sysDepart.getOrgCode()).eq("alarm_status", 1);
            Long yslLong1 = yslyjMapper.selectCount(queryWrapper81);

            Long total = cgkLong + csLong + dbcxLong + dbsLong + jslLong + pslLong + wzLong + yslLong;
            Long noHandle = cgkLong1 + csLong1 + dbcxLong1 + dbsLong1 + jslLong1 + pslLong1 + wzLong1 + yslLong1;
            Long handle = total - noHandle;
            list.add(noHandle.intValue());
            list.add(handle.intValue());
        }
        return list;
    }

    /**
     * 大屏异常统计
     *
     * @return
     */
    @Override
    public List<Integer> getCount() {
        String[] strings = {"140421005184", "140421005108"};
        List<Integer> list1 = new ArrayList<>();
        for (String string : strings) {
            List<Integer> list = getCategoryCount(string);
            int total = 0;
            for (Integer integer : list) {
                total += integer;
            }
            list1.add(total);
        }
        return list1;
    }

    /**
     * 大屏二矿异常统计
     *
     * @return
     */
    @Override
    public List<Integer> getCategoryCount(String code) {
        List<Integer> list = new ArrayList<>();
        String str = "140421005184";
        switch (code) {
            case "0":
                str = "5";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str = "140421005108";
                break;
        }
        QueryWrapper<Cgkyj> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("station_mine", str);
        Long cgkLong = cgkyjMapper.selectCount(queryWrapper1);
        list.add(cgkLong.intValue());
        QueryWrapper<Csyj> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("station_mine", str);
        Long csLong = csyjMapper.selectCount(queryWrapper2);
        list.add(csLong.intValue());
        QueryWrapper<Dbcxyj> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.eq("station_mine", str);
        Long dbcxLong = dbcxyjMapper.selectCount(queryWrapper3);
        list.add(dbcxLong.intValue());
        QueryWrapper<Dbsyj> queryWrapper4 = new QueryWrapper<>();
        queryWrapper4.eq("station_mine", str);
        Long dbsLong = dbsyjMapper.selectCount(queryWrapper4);
        list.add(dbsLong.intValue());
        QueryWrapper<Jslyj> queryWrapper5 = new QueryWrapper<>();
        queryWrapper5.eq("station_mine", str);
        Long jslLong = jslyjMapper.selectCount(queryWrapper5);
        list.add(jslLong.intValue());
        QueryWrapper<Pslyj> queryWrapper6 = new QueryWrapper<>();
        queryWrapper6.eq("station_mine", str);
        Long pslLong = pslyjMapper.selectCount(queryWrapper6);
        list.add(pslLong.intValue());
        QueryWrapper<Wzyj> queryWrapper7 = new QueryWrapper<>();
        queryWrapper7.eq("station_mine", str);
        Long wzLong = wzyjMapper.selectCount(queryWrapper7);
        list.add(wzLong.intValue());
        QueryWrapper<Yslyj> queryWrapper8 = new QueryWrapper<>();
        queryWrapper8.eq("station_mine", str);
        Long yslLong = yslyjMapper.selectCount(queryWrapper8);
        list.add(yslLong.intValue());
        return list;
    }

    /**
     * 集团预警信息统计
     *
     * @return
     */
    @Override
    public List<LargeDto> getAlarms() {
        List<LargeDto> largeDtos = new ArrayList<>();
        LargeDto largeDto1 = new LargeDto();
        largeDto1.setAlarmLevel1(cgkcdycMapper.getCountLevel1());
        largeDto1.setAlarmLevel2(cgkcdycMapper.getCountLevel2());
        largeDto1.setAlarmLevel3(cgkcdycMapper.getCountLevel3());
        largeDto1.setAlarmLevel4(cgkcdycMapper.getCountLevel4());
        largeDtos.add(largeDto1);
        LargeDto largeDto2 = new LargeDto();
        largeDto2.setAlarmLevel1(csyjMapper.getCountLevel1());
        largeDto2.setAlarmLevel2(csyjMapper.getCountLevel2());
        largeDto2.setAlarmLevel3(csyjMapper.getCountLevel3());
        largeDto2.setAlarmLevel4(csyjMapper.getCountLevel4());
        largeDtos.add(largeDto2);
        LargeDto largeDto3 = new LargeDto();
        largeDto3.setAlarmLevel1(dbcxyjMapper.getCountLevel1());
        largeDto3.setAlarmLevel2(dbcxyjMapper.getCountLevel2());
        largeDto3.setAlarmLevel3(dbcxyjMapper.getCountLevel3());
        largeDto3.setAlarmLevel4(dbcxyjMapper.getCountLevel4());
        largeDtos.add(largeDto3);
        LargeDto largeDto4 = new LargeDto();
        largeDto4.setAlarmLevel1(dbsyjMapper.getCountLevel1());
        largeDto4.setAlarmLevel2(dbsyjMapper.getCountLevel2());
        largeDto4.setAlarmLevel3(dbsyjMapper.getCountLevel3());
        largeDto4.setAlarmLevel4(dbsyjMapper.getCountLevel4());
        largeDtos.add(largeDto4);
        LargeDto largeDto5 = new LargeDto();
        largeDto5.setAlarmLevel1(jslyjMapper.getCountLevel1());
        largeDto5.setAlarmLevel2(jslyjMapper.getCountLevel2());
        largeDto5.setAlarmLevel3(jslyjMapper.getCountLevel3());
        largeDto5.setAlarmLevel4(jslyjMapper.getCountLevel4());
        largeDtos.add(largeDto5);
        LargeDto largeDto6 = new LargeDto();
        largeDto6.setAlarmLevel1(pslcdycMapper.getCountLevel1());
        largeDto6.setAlarmLevel2(pslcdycMapper.getCountLevel2());
        largeDto6.setAlarmLevel3(pslcdycMapper.getCountLevel3());
        largeDto6.setAlarmLevel4(pslcdycMapper.getCountLevel4());
        largeDtos.add(largeDto6);
        LargeDto largeDto7 = new LargeDto();
        largeDto7.setAlarmLevel1(wzyjMapper.getCountLevel1());
        largeDto7.setAlarmLevel2(wzyjMapper.getCountLevel2());
        largeDto7.setAlarmLevel3(wzyjMapper.getCountLevel3());
        largeDto7.setAlarmLevel4(wzyjMapper.getCountLevel4());
        largeDtos.add(largeDto7);
        LargeDto largeDto8 = new LargeDto();
        largeDto8.setAlarmLevel1(yslyjMapper.getCountLevel1());
        largeDto8.setAlarmLevel2(yslyjMapper.getCountLevel2());
        largeDto8.setAlarmLevel3(yslyjMapper.getCountLevel3());
        largeDto8.setAlarmLevel4(yslyjMapper.getCountLevel4());
        largeDtos.add(largeDto8);
        return largeDtos;
    }

    /**
     * 实时通知
     *
     * @return
     */
    @Override
    public List<ImmediateNoticeDto> getImmediateNotice(String code, String codestationMine) {
        List<ImmediateNoticeDto> immediateNoticeDtoList = new ArrayList<>();
        switch (code) {
            case "0":
                immediateNoticeDtoList = switchAll(codestationMine);
                break;
            case "1":
                immediateNoticeDtoList = switchPslcdss(codestationMine);
                break;
            case "2":
                immediateNoticeDtoList = switchCscdss(codestationMine);
                break;
            case "3":
                immediateNoticeDtoList = switchCgkcdss(codestationMine);
                break;
            case "4":
                immediateNoticeDtoList = switchWzcdss(codestationMine);
                break;
            case "5":
                immediateNoticeDtoList = switchJsldss(codestationMine);
                break;
            case "6":
                immediateNoticeDtoList = switchDbcx(codestationMine);
                break;
            case "7":
                immediateNoticeDtoList = switchDbscdss(codestationMine);
                break;
            case "8":
                immediateNoticeDtoList = switchYslcdss(codestationMine);
                break;
        }
        return immediateNoticeDtoList;
    }

    /**
     * 实时通知排水量
     *
     * @return
     */
    List<ImmediateNoticeDto> switchPslcdss(String codestationMine) {
        List<ImmediateNoticeDto> immediateNoticeDtoList = new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        String str = "140421005184";
        switch (codestationMine) {
            case "0":
                str = "all";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        QueryWrapper<Pslcdss> queryWrapperPslcdss = new QueryWrapper<>();
        if ("all".equals(str)) {
        } else {
            queryWrapperPslcdss.eq("station_mine", str);
        }
        queryWrapperPslcdss.between("monitor_time", timeStart, timeEnd);
        List<Pslcdss> pslcdssList = pslcdssMapper.selectList(queryWrapperPslcdss);
        AtomicInteger atomicNum = new AtomicInteger(1);
        pslcdssList.stream().map(pslcdss -> {
            ImmediateNoticeDto immediateNoticeDto = new ImmediateNoticeDto();
            immediateNoticeDto.setSerialNumber(String.valueOf(atomicNum.getAndIncrement()));
            immediateNoticeDto.setType("排水量");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            immediateNoticeDto.setMonitoringTime(sdf.format(pslcdss.getMonitorTime()));
            immediateNoticeDto.setValue(pslcdss.getValue().toString());
            immediateNoticeDtoList.add(immediateNoticeDto);
            return null;
        }).collect(Collectors.toList());
        return immediateNoticeDtoList;
    }

    /**
     * 实时通知疏放水
     *
     * @return
     */
    List<ImmediateNoticeDto> switchCscdss(String codestationMine) {
        List<ImmediateNoticeDto> immediateNoticeDtoList = new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Cscdss> queryWrapperCscdss = new QueryWrapper<>();
        String str = "140421005184";
        switch (codestationMine) {
            case "0":
                str = "all";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        } else {
            queryWrapperCscdss.eq("station_mine", str);
        }
        queryWrapperCscdss.between("data_time", timeStart, timeEnd);
        List<Cscdss> cscdssList = cscdssMapper.selectList(queryWrapperCscdss);
        AtomicInteger atomicNumCscdss = new AtomicInteger(1);
        cscdssList.stream().map(cscdss -> {
            ImmediateNoticeDto immediateNoticeDto = new ImmediateNoticeDto();
            immediateNoticeDto.setSerialNumber(String.valueOf(atomicNumCscdss.getAndIncrement()));
            immediateNoticeDto.setType("疏放水");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            immediateNoticeDto.setMonitoringTime(sdf.format(cscdss.getDataTime()));
            immediateNoticeDto.setValue(cscdss.getDrainageAmount().toString());
            immediateNoticeDtoList.add(immediateNoticeDto);
            return null;
        }).collect(Collectors.toList());
        return immediateNoticeDtoList;
    }

    /**
     * 实时通知长观孔
     *
     * @return
     */
    List<ImmediateNoticeDto> switchCgkcdss(String codestationMine) {
        List<ImmediateNoticeDto> immediateNoticeDtoList = new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Cgkcdss> queryWrapperCgkcdss = new QueryWrapper<>();
        String str = "140421005184";
        switch (codestationMine) {
            case "0":
                str = "all";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        } else {
            queryWrapperCgkcdss.eq("org_code", str);
        }
        queryWrapperCgkcdss.between("monitor_time", timeStart, timeEnd);
        List<Cgkcdss> cgkcdssList = cgkcdssMapper.selectList(queryWrapperCgkcdss);
        AtomicInteger atomicNumCgkcdss = new AtomicInteger(1);
        cgkcdssList.stream().map(cgkcdss -> {
            ImmediateNoticeDto immediateNoticeDto = new ImmediateNoticeDto();
            immediateNoticeDto.setSerialNumber(String.valueOf(atomicNumCgkcdss.getAndIncrement()));
            immediateNoticeDto.setType("长观孔");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            immediateNoticeDto.setMonitoringTime(sdf.format(cgkcdss.getMonitorTime()));
            immediateNoticeDto.setValue(cgkcdss.getWaterLevel().toString());
            immediateNoticeDtoList.add(immediateNoticeDto);
            return null;
        }).collect(Collectors.toList());
        return immediateNoticeDtoList;
    }

    /**
     * 实时通知微震
     *
     * @return
     */
    List<ImmediateNoticeDto> switchWzcdss(String codestationMine) {
        List<ImmediateNoticeDto> immediateNoticeDtoList = new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Wzcdss> queryWrapperWzcdss = new QueryWrapper<>();
        String str = "140421005184";
        switch (codestationMine) {
            case "0":
                str = "all";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        } else {
            queryWrapperWzcdss.eq("station_mine", str);
        }
        queryWrapperWzcdss.between("occurred_time", timeStart, timeEnd);
        List<Wzcdss> wzcdssList = wzcdssMapper.selectList(queryWrapperWzcdss);
        AtomicInteger atomicNumWzcdss = new AtomicInteger(1);
        wzcdssList.stream().map(wzcdss -> {
            ImmediateNoticeDto immediateNoticeDto = new ImmediateNoticeDto();
            immediateNoticeDto.setSerialNumber(String.valueOf(atomicNumWzcdss.getAndIncrement()));
            immediateNoticeDto.setType("微震");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            immediateNoticeDto.setMonitoringTime(sdf.format(wzcdss.getOccurredTime()));
            immediateNoticeDto.setValue(wzcdss.getSeismicEnergy().toString());
            immediateNoticeDtoList.add(immediateNoticeDto);
            return null;
        }).collect(Collectors.toList());
        return immediateNoticeDtoList;
    }

    /**
     * 实时通知降水量
     *
     * @return
     */
    List<ImmediateNoticeDto> switchJsldss(String codestationMine) {
        List<ImmediateNoticeDto> immediateNoticeDtoList = new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Jslcdss> queryWrapperJslcdss = new QueryWrapper<>();
        String str = "140421005184";
        switch (codestationMine) {
            case "0":
                str = "all";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        } else {
            queryWrapperJslcdss.eq("station_mine", str);
        }
        queryWrapperJslcdss.between("monitor_time", timeStart, timeEnd);
        List<Jslcdss> jslcdssList = jslcdssMapper.selectList(queryWrapperJslcdss);
        AtomicInteger atomicNumJslcdss = new AtomicInteger(1);
        jslcdssList.stream().map(jslcdss -> {
            ImmediateNoticeDto immediateNoticeDto = new ImmediateNoticeDto();
            immediateNoticeDto.setSerialNumber(String.valueOf(atomicNumJslcdss.getAndIncrement()));
            immediateNoticeDto.setType("降水量");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            immediateNoticeDto.setMonitoringTime(sdf.format(jslcdss.getMonitorTime()));
            immediateNoticeDto.setValue(jslcdss.getValue().toString());
            immediateNoticeDtoList.add(immediateNoticeDto);
            return null;
        }).collect(Collectors.toList());
        return immediateNoticeDtoList;
    }

    /**
     * 实时通知地表岩移
     *
     * @return
     */
    List<ImmediateNoticeDto> switchDbcx(String codestationMine) {
        List<ImmediateNoticeDto> immediateNoticeDtoList = new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Dbcxcdss> queryWrapperDbcxcdss = new QueryWrapper<>();
        String str = "140421005184";
        switch (codestationMine) {
            case "0":
                str = "all";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        } else {
            queryWrapperDbcxcdss.eq("station_mine", str);
        }
        queryWrapperDbcxcdss.between("data_time", timeStart, timeEnd);
        List<Dbcxcdss> dbcxcdssList = dbcxcdssMapper.selectList(queryWrapperDbcxcdss);
        AtomicInteger atomicNumDbcxcdss = new AtomicInteger(1);
        dbcxcdssList.stream().map(dbcxcdss -> {
            ImmediateNoticeDto immediateNoticeDto = new ImmediateNoticeDto();
            immediateNoticeDto.setSerialNumber(String.valueOf(atomicNumDbcxcdss.getAndIncrement()));
            immediateNoticeDto.setType("地表岩移");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            immediateNoticeDto.setMonitoringTime(sdf.format(dbcxcdss.getDataTime()));
            immediateNoticeDto.setValue(dbcxcdss.getMiningDepth());
            immediateNoticeDtoList.add(immediateNoticeDto);
            return null;
        }).collect(Collectors.toList());
        return immediateNoticeDtoList;
    }

    /**
     * 实时通知地表水
     *
     * @return
     */
    List<ImmediateNoticeDto> switchDbscdss(String codestationMine) {
        List<ImmediateNoticeDto> immediateNoticeDtoList = new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Dbscdss> queryWrapperDbscdss = new QueryWrapper<>();
        String str = "140421005184";
        switch (codestationMine) {
            case "0":
                str = "all";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        } else {
            queryWrapperDbscdss.eq("station_mine", str);
        }
        queryWrapperDbscdss.between("monitor_time", timeStart, timeEnd);
        List<Dbscdss> dbscdssList = dbscdssMapper.selectList(queryWrapperDbscdss);
        AtomicInteger atomicNumDbscdss = new AtomicInteger(1);
        dbscdssList.stream().map(dbscdss -> {
            ImmediateNoticeDto immediateNoticeDto = new ImmediateNoticeDto();
            immediateNoticeDto.setSerialNumber(String.valueOf(atomicNumDbscdss.getAndIncrement()));
            immediateNoticeDto.setType("地表水");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            immediateNoticeDto.setMonitoringTime(sdf.format(dbscdss.getMonitorTime()));
            immediateNoticeDto.setValue(dbscdss.getValue().toString());
            immediateNoticeDtoList.add(immediateNoticeDto);
            return null;
        }).collect(Collectors.toList());
        return immediateNoticeDtoList;
    }

    /**
     * 实时通知涌水量
     *
     * @return
     */
    List<ImmediateNoticeDto> switchYslcdss(String codestationMine) {
        List<ImmediateNoticeDto> immediateNoticeDtoList = new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Yslcdss> queryWrapperYslcdss = new QueryWrapper<>();
        String str = "140421005184";
        switch (codestationMine) {
            case "0":
                str = "all";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        } else {
            queryWrapperYslcdss.eq("station_mine", str);
        }
        queryWrapperYslcdss.between("monitor_time", timeStart, timeEnd);
        List<Yslcdss> yslcdssList = yslcdssMapper.selectList(queryWrapperYslcdss);
        AtomicInteger atomicNumYslcdss = new AtomicInteger(1);
        yslcdssList.stream().map(yslcdss -> {
            ImmediateNoticeDto immediateNoticeDto = new ImmediateNoticeDto();
            immediateNoticeDto.setSerialNumber(String.valueOf(atomicNumYslcdss.getAndIncrement()));
            immediateNoticeDto.setType("涌水量");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            immediateNoticeDto.setMonitoringTime(sdf.format(yslcdss.getMonitorTime()));
            immediateNoticeDto.setValue(yslcdss.getValue());
            immediateNoticeDtoList.add(immediateNoticeDto);
            return null;
        }).collect(Collectors.toList());
        return immediateNoticeDtoList;
    }

    /**
     * 实时通知所有
     *
     * @return
     */
    List<ImmediateNoticeDto> switchAll(String codestationMine) {
        List<ImmediateNoticeDto> immediateNoticeDtoList = new ArrayList<>();
        List<ImmediateNoticeDto> list1 = switchCgkcdss(codestationMine);
        list1.stream().forEach(dto1 -> {
            immediateNoticeDtoList.add(dto1);
        });
        List<ImmediateNoticeDto> list2 = switchJsldss(codestationMine);
        list2.stream().forEach(dto2 -> {
            immediateNoticeDtoList.add(dto2);
        });
        List<ImmediateNoticeDto> list3 = switchPslcdss(codestationMine);
        list3.stream().forEach(dto1 -> {
            immediateNoticeDtoList.add(dto1);
        });
        List<ImmediateNoticeDto> list4 = switchCscdss(codestationMine);
        list4.stream().forEach(dto1 -> {
            immediateNoticeDtoList.add(dto1);
        });
        List<ImmediateNoticeDto> list5 = switchWzcdss(codestationMine);
        list5.stream().forEach(dto1 -> {
            immediateNoticeDtoList.add(dto1);
        });
        List<ImmediateNoticeDto> list6 = switchDbcx(codestationMine);
        list6.stream().forEach(dto1 -> {
            immediateNoticeDtoList.add(dto1);
        });
        List<ImmediateNoticeDto> list7 = switchDbscdss(codestationMine);
        list7.stream().forEach(dto1 -> {
            immediateNoticeDtoList.add(dto1);
        });
        List<ImmediateNoticeDto> list8 = switchYslcdss(codestationMine);
        list8.stream().forEach(dto1 -> {
            immediateNoticeDtoList.add(dto1);
        });
        AtomicInteger atomicNum = new AtomicInteger(1);
        immediateNoticeDtoList.stream().forEach(immediateNoticeDto -> {
            immediateNoticeDto.setSerialNumber(String.valueOf(atomicNum.getAndIncrement()));
            immediateNoticeDto.setType(immediateNoticeDto.getType());
            immediateNoticeDto.setMonitoringTime(immediateNoticeDto.getMonitoringTime());
            immediateNoticeDto.setValue(immediateNoticeDto.getValue());
        });
        return immediateNoticeDtoList;
    }

    /**
     * 监测信息统计
     *
     * @return
     */
    @Override
    public List<MonitoringInformation> getmonitoringInformation(String code) {
        List<MonitoringInformation> monitoringInformationList=new ArrayList<>();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDate today = LocalDate.now();
        String timeStart="1900-01-01";
        String timeEnd="2100-12-31";
        String str="140421005184";
        switch (code){
            case "0":
                str = "all";
                break;
            case "140421005184":
                str = "140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
            QueryWrapper<SysDepart> sysDepartQueryWrapper=new QueryWrapper<>();
            sysDepartQueryWrapper.ne("parent_id","");
            List<SysDepart> sysDepartList=sysDepartMapper.selectList(sysDepartQueryWrapper);
            sysDepartList.stream().map(dto->{
                List<MonitoringInformation> monitoringInformationListDto = new ArrayList<>();
                monitoringInformationListDto = getmonitoringInformation(dto.getOrgCode());
                monitoringInformationList.addAll(monitoringInformationListDto);
                return true;
            }).collect(Collectors.toList());
            return monitoringInformationList;
        } else {
            QueryWrapper<SysDepart> sysDepartQueryWrapper=new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code",str);
            SysDepart sysDepart=sysDepartMapper.selectList(sysDepartQueryWrapper).get(0);
            //长观孔
            MonitoringInformation monitoringInformationCgk = new MonitoringInformation();
            QueryWrapper<Cgkcdss> queryWrapperCgkcdss = new QueryWrapper<>();
//        queryWrapperCgkcdss.between("monitor_time",timeStart,timeEnd);
            if ("all".equals(str)) {
            } else {
                queryWrapperCgkcdss.eq("org_code", str);
            }
            Long monitoringRecordsCgkcdss = cgkcdssMapper.selectCount(queryWrapperCgkcdss);
            QueryWrapper<Cgkyj> queryWrapperCgkyj = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperCgkyj.eq("station_mine", str);
            }
            Long abnormalNumberCgk = cgkyjMapper.selectCount(queryWrapperCgkyj);
            monitoringInformationCgk.setName("长观孔");
            monitoringInformationCgk.setNormal(String.valueOf(monitoringRecordsCgkcdss));
            monitoringInformationCgk.setAbnormal(String.valueOf(abnormalNumberCgk));
            monitoringInformationCgk.setMine(sysDepart.getDepartName());
            monitoringInformationList.add(monitoringInformationCgk);
            //抽放水
            QueryWrapper<Cscdss> queryWrapperCscdss = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperCscdss.eq("station_mine", str);
            }
            Long monitoringRecordsCscdss = cscdssMapper.selectCount(queryWrapperCscdss);
            QueryWrapper<Csyj> queryWrapperCsyj = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperCsyj.eq("station_mine", str);
            }
            Long abnormalNumberCs = csyjMapper.selectCount(queryWrapperCsyj);
            MonitoringInformation monitoringInformationCs = new MonitoringInformation();
            monitoringInformationCs.setName("抽放水");
            monitoringInformationCs.setNormal(String.valueOf(monitoringRecordsCscdss));
            monitoringInformationCs.setAbnormal(String.valueOf(abnormalNumberCs));
            monitoringInformationCs.setMine(sysDepart.getDepartName());
            monitoringInformationList.add(monitoringInformationCs);
            //地表沉陷
            QueryWrapper<Dbcxcdss> queryWrapperDbcxcdss = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperDbcxcdss.eq("station_mine", str);
            }
            Long monitoringRecordsDbcxcdss = dbcxcdssMapper.selectCount(queryWrapperDbcxcdss);
            QueryWrapper<Dbcxyj> queryWrapperDbcxyj = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperDbcxyj.eq("station_mine", str);
            }
            Long abnormalNumberDbcx = dbcxyjMapper.selectCount(queryWrapperDbcxyj);
            MonitoringInformation monitoringInformationDbcx = new MonitoringInformation();
            monitoringInformationDbcx.setName("岩移&emsp;");
            monitoringInformationDbcx.setNormal(String.valueOf(monitoringRecordsDbcxcdss));
            monitoringInformationDbcx.setAbnormal(String.valueOf(abnormalNumberDbcx));
            monitoringInformationDbcx.setMine(sysDepart.getDepartName());
            monitoringInformationList.add(monitoringInformationDbcx);
            //地表水
            QueryWrapper<Dbscdss> queryWrapperDbscdss = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperDbscdss.eq("station_mine", str);
            }
            Long monitoringRecordsDbscdss = dbscdssMapper.selectCount(queryWrapperDbscdss);
            QueryWrapper<Dbsyj> queryWrapperDbsyj = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperDbsyj.eq("station_mine", str);
            }
            Long abnormalNumberDbs = dbsyjMapper.selectCount(queryWrapperDbsyj);
            MonitoringInformation monitoringInformationDbs = new MonitoringInformation();
            monitoringInformationDbs.setName("地表水");
            monitoringInformationDbs.setNormal(String.valueOf(monitoringRecordsDbscdss));
            monitoringInformationDbs.setAbnormal(String.valueOf(abnormalNumberDbs));
            monitoringInformationDbs.setMine(sysDepart.getDepartName());
            monitoringInformationList.add(monitoringInformationDbs);
            //降水量
            QueryWrapper<Jslcdss> queryWrapperJslcdss = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperJslcdss.eq("station_mine", str);
            }
            Long monitoringRecordsJslcdss = jslcdssMapper.selectCount(queryWrapperJslcdss);
            QueryWrapper<Jslyj> queryWrapperJslyj = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperJslyj.eq("station_mine", str);
            }
            Long abnormalNumberJsl = jslyjMapper.selectCount(queryWrapperJslyj);
            MonitoringInformation monitoringInformationJsl = new MonitoringInformation();
            monitoringInformationJsl.setName("降水量");
            monitoringInformationJsl.setNormal(String.valueOf(monitoringRecordsJslcdss));
            monitoringInformationJsl.setAbnormal(String.valueOf(abnormalNumberJsl));
            monitoringInformationJsl.setMine(sysDepart.getDepartName());
            monitoringInformationList.add(monitoringInformationJsl);
            //排水量
            QueryWrapper<Pslcdss> queryWrapperPslcdss = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperPslcdss.eq("station_mine", str);
            }
            Long monitoringRecordsPslcdss = pslcdssMapper.selectCount(queryWrapperPslcdss);
            QueryWrapper<Pslyj> queryWrapperPslyj = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperPslyj.eq("station_mine", str);
            }
            Long abnormalNumberPsl = pslyjMapper.selectCount(queryWrapperPslyj);
            MonitoringInformation monitoringInformationPsl = new MonitoringInformation();
            monitoringInformationPsl.setName("排水量");
            monitoringInformationPsl.setNormal(String.valueOf(monitoringRecordsPslcdss));
            monitoringInformationPsl.setAbnormal(String.valueOf(abnormalNumberPsl));
            monitoringInformationPsl.setMine(sysDepart.getDepartName());
            monitoringInformationList.add(monitoringInformationPsl);
            //微震
            QueryWrapper<Wzcdss> queryWrapperWzcdss = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperWzcdss.eq("station_mine", str);
            }
            Long monitoringRecordsWzcdss = wzcdssMapper.selectCount(queryWrapperWzcdss);
            QueryWrapper<Wzyj> queryWrapperWzyj = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperWzyj.eq("station_mine", str);
            }
            Long abnormalNumberWz = wzyjMapper.selectCount(queryWrapperWzyj);
            MonitoringInformation monitoringInformationWz = new MonitoringInformation();
            monitoringInformationWz.setName("微震&emsp;");
            monitoringInformationWz.setNormal(String.valueOf(monitoringRecordsWzcdss));
            monitoringInformationWz.setAbnormal(String.valueOf(abnormalNumberWz));
            monitoringInformationWz.setMine(sysDepart.getDepartName());
            monitoringInformationList.add(monitoringInformationWz);
            //涌水量
            QueryWrapper<Yslcdss> queryWrapperYslcdss = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperYslcdss.eq("station_mine", str);
            }
            Long monitoringRecordsYslcdss = yslcdssMapper.selectCount(queryWrapperYslcdss);
            QueryWrapper<Yslyj> queryWrapperYslyj = new QueryWrapper<>();
            if ("all".equals(str)) {
            } else {
                queryWrapperYslyj.eq("station_mine", str);
            }
            Long abnormalNumberYsl = yslyjMapper.selectCount(queryWrapperYslyj);
            MonitoringInformation monitoringInformationYsl = new MonitoringInformation();
            monitoringInformationYsl.setName("涌水量");
            monitoringInformationYsl.setNormal(String.valueOf(monitoringRecordsYslcdss));
            monitoringInformationYsl.setAbnormal(String.valueOf(abnormalNumberYsl));
            monitoringInformationYsl.setMine(sysDepart.getDepartName());
            monitoringInformationList.add(monitoringInformationYsl);

            return monitoringInformationList;
        }
    }
}
